<?php
/**
* @package      com_flexam for Joomla! 1.5
* @version	$Id: flexam.php 2010-04-02 10:07:31Z Hernán Roa $
* @author       Hernán Roa Reyes
* @copyright	(C) 2010 - 2012 Hernán Roa Reyes.
* @license	GNU/GPLv3 http://www.gnu.org/copyleft/gpl.html
* See license.txt
* flexam is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
*/

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die( 'Restricted access' );

jimport( 'joomla.application.component.controller' );

/**
 * @package		Joomla
 * @subpackage	Config
 */
class flExamControllerCfg extends JController{
	/**
	 * Custom Constructor
	 */
	function __construct( $default = array()){
		parent::__construct( $default );
	}

        function display( ){
            if(JRequest::getVar('task') == 'remove'){
                $this->remove();
            }

            if(JRequest::getVar('task') == 'save'){
                $this->save();
            }

            //Set the default view, just in case
            $view = JRequest::getCmd('view');

            if(empty($view)) {
                    JRequest::setVar('view', 'cfg');
            };
            
            parent::display();
	}

	function remove(){
		// Check for request forgeries
		JRequest::checkToken() or jexit( 'Invalid Token' );

		$db  =& JFactory::getDBO();

		$msg = '';

		$qry = "UPDATE #__flexam_connconfig SET value=''";
                $db->setQuery($qry);

                if (!$db->query())	{
                    $msg .= $answ->getError();
                }

		$this->setRedirect( 'index.php?option=com_flexam&optCtrl=mainFlCfg', $msg );
	}

	function save(){
            // Check for request forgeries
            //JRequest::checkToken() or jexit( 'Invalid Token' );

            $db         =& JFactory::getDBO();
            $post       = JRequest::get( 'post' );

            $obj = new stdClass();

            for($i = 1; $i < 7; $i++){
                $qry = "UPDATE #__flexam_connconfig SET " .
                    "value='".$post["cfgV$i"]."' WHERE idcgf='$i'";
                
                $db->setQuery($qry);
                $db->query();
            }

            $this->setRedirect( 'index.php?option=com_flexam&optCtrl=mainFlCfg' );
        }
}